/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.coupon.controller.b;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.entity.CnShop;
import com.ykht.proj.coupon.service.CnShopService;
import com.ykht.proj.coupon.vo.CnShopVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * 店铺表
 *
 * @author proj code generator
 * @date 2020-11-18 17:10:45
 */
@RestController
@AllArgsConstructor
@RequestMapping("/b/cnshop")
@Api(value = "cnshop", tags = "店铺表管理")
@Slf4j
public class BnShopController {

	private final CnShopService cnShopService;

	/**
	 * 获取创建活动的门店
	 *
	 * @param labelId  标签ID
	 * @param shopName 门店名称
	 * @return
	 */
	@ApiOperation(value = "获取创建活动的门店")
	@GetMapping("getShop")
	public R getShop(Long labelId, String shopName) {
		List<CnShop> shopList = new ArrayList<>();
		if (labelId != null) {
			shopList = cnShopService.getActivityShop(labelId, shopName);
		} else {
			QueryWrapper<CnShop> queryWrapper = new QueryWrapper<>();
			queryWrapper.lambda().eq(CnShop::getDisplay, 0);
			if (null != shopName && !"".equals(shopName)) {
				queryWrapper.lambda().like(CnShop::getName, shopName);
			}
			queryWrapper.lambda().orderByDesc(CnShop::getCreateTime);
			shopList = cnShopService.list(queryWrapper);
		}
		return R.ok(shopList);
	}


	/**
	 * 获取登录人的门店信息
	 *
	 * @return R
	 */
	@ApiOperation("获取登录人的门店信息")
	@PostMapping("/getByLoginIdShop")
	public CnShop getByLoginIdShop() {
		return cnShopService.getById(SecurityUtils.getSjId());
	}


	/**
	 * 根据ID集合 获取门店
	 *
	 * @return R
	 */
	@ApiOperation("根据ID集合 获取门店")
	@PostMapping("/getByIds")
	public List<CnShop> getByIds(@RequestBody String[] ids) {
		return cnShopService.list(new QueryWrapper<CnShop>().lambda().in(CnShop::getId, ids));
	}


	/**
	 * 获取登录人的门店信息
	 *
	 * @return R
	 */
	@ApiOperation("获取登录人的门店信息")
	@PostMapping("/getById/{id}")
	public CnShop getById(@PathVariable("id") Long id) {
		return cnShopService.getById(id);
	}

	/**
	 * 根据门店ID获取全部门店信息
	 *
	 * @return R
	 */
	@ApiOperation("根据门店ID获取全部门店信息")
	@PostMapping("/getByShopId/{shopId}")
	public CnShopVo getByShopId(@PathVariable("shopId") Long shopId) {
		return cnShopService.getByShopId(shopId);
	}

}
